<template>
    <div class="wrapper12">
        <header>
            <p>编辑送货地址</p>
        </header>
    </div>
    <ul class="form-box">
      <li class="li1">
        <div class="title">联系人：</div>
        <div class="content">
            <input type="text" v-model="deliveryAddress.contactName" placeholder="联系人姓名" class="input">
        </div>
      </li>
      <li class="li1">
        <div class="title">
            性别：
        </div>
        <div class="content" >
            <input type="radio" v-model="deliveryAddress.contactSex" value="1"  checked>男
            <input type="radio"  v-model="deliveryAddress.contactSex" value="0">女

        </div>

      </li>
      <li class="li1">
        <div class="title">电话：</div>
        <div class="content">
            <input type="text" v-model="deliveryAddress.contactTel" placeholder="电话" class="input">

        </div>
      </li>
      <li class="li1">
        <div class="title">收货地址：</div>
        <div class="content">
            <input type="text" v-model="deliveryAddress.address" placeholder="收货地址" class="input">
        </div>
      </li>
    </ul>
    <div class="button-add">
        <button @click="editUserAddress">更新</button>
    </div>
    <Footer></Footer>
</template>

<script>
export default{
    name:'EditUserAddress',
    data(){
       return{
        businessId:this.$route.query.businessId,
        daId:this.$route.query.daId,
        user:{},
        deliveryAddress:{}
       }
    },
    created(){
        this.user = this.$getSessionStorage('user');
        this.$axios.post('DeliveryAddressController/getDeliveryAddressById',this.$qs.stringify({
            daId: this.daId
        })).then(response =>{
            this.deliveryAddress = response.data;
        }).catch(error =>{
            console.error(error);
            
        })
    },
    methods:{
        editUserAddress(){
            if(this.deliveryAddress.contactName ==''){
                alert("姓名不能为空");
                return;
            }
            if(this.deliveryAddress.contactTel ==''){
                alert("电话不能为空");
                return;
            }
            if(this.deliveryAddress.address ==''){
                alert("地址不能为空");
                return;
            }
            this.$axios.post('DeliveryAddressController/updateDeliveryAddress',this.$qs.stringify(
                this.deliveryAddress
            )).then(response =>{
                if(response.data>0){
                    this.$router.push({
                        path:'/userAddress',
                        query:{
                            businessId:this.businessId
                        }
                    });
                }else{
                    alert("更新失败")
                }
            }).catch(error =>{
                console.error(error);
            })
        }
    }
}
</script>
<style>
.wrapper12{
    width: 100%;
    height: 100px;
    font-size: 50px;
    background-color: #0097ff;
  
    color: white;
    text-align: center;

}
.li1{
    display: flex;
    margin-top: 10px;
    font-size: 30px;
}
.input{
    width: 800px;
    height: 40px;
    font-size: 25px;
}
.content{
    display: flex;
    width: 30px;

}
button{
    width: 100px;
    height: 80px;
    font-size: 30px;
    color: white;
    background-color: #0097ff;
}
</style>